package top.zhangjianyong.tools.reptile;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

/**
 * @author ： zhangjianyong
 * @date ： 2023/3/22 10:36 AM
 */
public class RequestUtil {
    public static HttpResult getHtml(String url) {
        HttpRequest get = HttpUtil.createGet(url);
        HttpResponse execute = get.execute();
        int status = execute.getStatus();
        HttpResult result = new HttpResult();
        if (status==302||status==301){
            result.setLocation(execute.header("location"));
        }
        result.setStatus(status);
        result.setBody(execute.body());

        return result;
    }


    public static void main(String[] args) {
        String url = "http://www.baidu.com";
        HttpResult html = getHtml(url);
        System.out.println(html);
    }
}
